import rq from 'request-promise'
import cheerio from 'cheerio'
import iconv from 'iconv-lite'
import { writeFileSync } from 'fs'
import { resolve } from 'path'

const r = path => resolve(__dirname, path)
// var nyou = require(r('../../nyou.json'))
// nyou = nyou.arr

const sleep = time => new Promise((resolve) => {
	return setTimeout(resolve, time)
})

const jiequ = v => v.length > 50 ? v.substring(0, 50) : v
const chongzhi = path => {
	path = path.split('.')
	return path[0]
}


var arr = []	// 任务数据
var page = 0	// 页数
var now = 0	// 当前任务
var errorTime = 0 // 失败次数
var pageNum = 18	//页面数据个数
var isclearTimer = false

const getApi = async () => {
  console.log(1)
	var peoples = []
	var url = `https://gz.meituan.com/meishi/c393`
	// console.log(url)
	const options = {
		url: url,
		encoding:null, //乱码关键代码
		transform: body => { 
			var html = iconv.decode(body,'gb2312')
			return cheerio.load(html, { decodeEntities:false}) 
		}
	}
	console.log(2)
  var $ = await rq(options)
  console.log($('#app').text())
	$('.list-ul li').each(function() {
		console.log($(this).find('a').attr('href'))
  })
}
getApi()
// const timer = setInterval(function() {
// 	getApi()
// },10000)

// const clearTime = setInterval(function() {
// 	if (isclearTimer) {
// 		clearInterval(timer)
// 	}
// },1000)